package com.jacobson.huobi.mvp

import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.text.AlteredCharSequence
import android.view.LayoutInflater
import android.widget.Toast
import com.jacobson.core.base.Immersive
import com.jacobson.core.di.components.AppComponent
import com.jacobson.core.di.modules.ActivityModule
import com.jacobson.core.mvp.BaseMvpActivity
import com.jacobson.huobi.R
import com.jacobson.huobi.di.components.DaggerContactUsActivityComponent
import com.jacobson.huobi.di.components.DaggerEditPasswordActivityComponent
import com.jacobson.huobi.di.modules.ContactUsActivityModule
import com.jacobson.huobi.di.modules.EditPasswordActivityModule
import com.jacobson.huobi.mvp.contract.ContactUsContract
import com.jacobson.huobi.mvp.contract.EditPasswordContract
import com.jacobson.huobi.utils.ResourcesUtil
import kotlinx.android.synthetic.main.activity_contact_us.*
import kotlinx.android.synthetic.main.activity_contact_us.view.*
import kotlinx.android.synthetic.main.activity_edit_password.*
import kotlinx.android.synthetic.main.activity_edit_password.btnBack
import kotlinx.android.synthetic.main.fragment_currency.*

@Immersive(fitSystemWindows = false)
class ContactUsActivity :
    BaseMvpActivity<ContactUsContract.Presenter>(), ContactUsContract.View {


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        //修改底部功能键背景色 只支持api为21及以上
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            window.navigationBarColor =
                ResourcesUtil.getColor(R.color.colorPrimary) //设定底部导航栏  同全局颜色
        }
    }

    override fun setupActivityComponent(appComponent: AppComponent) {
        DaggerContactUsActivityComponent.builder()
            .contactUsActivityModule(ContactUsActivityModule(this))
            .appComponent(appComponent)
            .activityModule(ActivityModule(this))
            .build()
            .inject(this)
//        DaggerAlarmRecordActivityComponent.builder()
//            .alarmRecordActivityModule(AlarmRecordActivityModule(this))
//            .appComponent(appComponent)
//            .activityModule(ActivityModule(this))
//            .build()
//            .inject(this)
    }

    override fun initView(savedInstanceState: Bundle?): Int = R.layout.activity_contact_us

    override fun initData(savedInstanceState: Bundle?) {
        initBtnClick()
//        with(recyclerView) {
//            layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
//            itemAnimator = DefaultItemAnimator()
////            addItemDecoration(SpaceItemDecoration(3f))
//            adapter = kycAuthAdapter
//        }
    }

    override fun onError(type: Int, extra: Any?, code: Int, message: String): Boolean {
        smartRefreshLayout.finishLoadMore()
        smartRefreshLayout.finishRefresh()
        logger.e("error >>> $message")
        return super.onError(type, extra, code, message)
    }

    private fun initBtnClick() {
//        LayoutInflater.from(this).inflate(R.layout.activity_contact_us, null, false)
        btnBack.setOnClickListener({
            this.finish()
//            this?.overridePendingTransition( R.anim.slide_right_out,R.anim.slide_left_in)
        })
        btnContactUsCpyQQ.setOnClickListener({
            var clipboardManager = this.getSystemService(CLIPBOARD_SERVICE) as ClipboardManager
            var clip = ClipData.newPlainText("text", tvContactUsQQ.text)
            clipboardManager.primaryClip = clip
            Toast.makeText(this, "复制成功", Toast.LENGTH_SHORT).show()
        })
        btnContactUsCpyWeChat.setOnClickListener({
            var clipboardManager = this.getSystemService(CLIPBOARD_SERVICE) as ClipboardManager
            var clip = ClipData.newPlainText("text", tvContactUsQQGroup.text)
            clipboardManager.primaryClip = clip
            Toast.makeText(this, "复制成功", Toast.LENGTH_SHORT).show()
        })
        btnContactUsCpyQQGroup.setOnClickListener({
            var clipboardManager = this.getSystemService(CLIPBOARD_SERVICE) as ClipboardManager
            var clip = ClipData.newPlainText("text", tvContactUsQQGroup.text)
            clipboardManager.primaryClip = clip
            Toast.makeText(this, "复制成功", Toast.LENGTH_SHORT).show()
        })

    }

    companion object {
        fun startActivity(context: Context) {
            Intent(context, ContactUsActivity::class.java).run {
                context.startActivity(this)
            }
        }

    }

}
